{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "#load数据（用户和物品索引，以及倒排表）\n",
    "import pickle\n",
    "import json  \n",
    "\n",
    "from numpy.random import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "#用户和item的索引\n",
    "users_index = pickle.load(open(\"users_index.pkl\", 'rb'))\n",
    "items_index = pickle.load(open(\"items_index.pkl\", 'rb'))\n",
    "\n",
    "n_users = len(users_index)\n",
    "n_items = len(items_index)\n",
    "    \n",
    "#用户-物品关系矩阵R\n",
    "#scores = sio.mmread(\"scores\").todense()\n",
    "    \n",
    "#倒排表\n",
    "##每个用户打过分的电影\n",
    "user_items = pickle.load(open(\"user_items.pkl\", 'rb'))\n",
    "##对每个电影打过分的事用户\n",
    "item_users = pickle.load(open(\"item_users.pkl\", 'rb'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user</th>\n",
       "      <th>song</th>\n",
       "      <th>play_count</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>7bdfc45af7e15511d150e2acb798cd5e4788abf5</td>\n",
       "      <td>SOXBCZH12A67ADAD77</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>c405c586f6d7aadbbadfcba5393b543fd99372ff</td>\n",
       "      <td>SOXFYTY127E9433E7D</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>625d0167edbc5df88e9fbebe3fcdd6b121a316bb</td>\n",
       "      <td>SONOYIB12A81C1F88C</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>20ad98ab543da9ec41c6ac3b6354c5ab3ca6bc5e</td>\n",
       "      <td>SOIMCDE12A6D4F8383</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>d331a8bf7d0ca9cb37e375496e6075603f6fb44a</td>\n",
       "      <td>SONYKOW12AB01849C9</td>\n",
       "      <td>40</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                       user                song  play_count\n",
       "0  7bdfc45af7e15511d150e2acb798cd5e4788abf5  SOXBCZH12A67ADAD77           8\n",
       "1  c405c586f6d7aadbbadfcba5393b543fd99372ff  SOXFYTY127E9433E7D           3\n",
       "2  625d0167edbc5df88e9fbebe3fcdd6b121a316bb  SONOYIB12A81C1F88C           1\n",
       "3  20ad98ab543da9ec41c6ac3b6354c5ab3ca6bc5e  SOIMCDE12A6D4F8383           1\n",
       "4  d331a8bf7d0ca9cb37e375496e6075603f6fb44a  SONYKOW12AB01849C9          40"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#读取训练数据\n",
    "df_triplet_train = pd.read_csv('df_triplet_train.csv')\n",
    "df_triplet_train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [],
   "source": [
    "#初始化模型参数\n",
    "#隐含变量的维数\n",
    "K = 40\n",
    "\n",
    "#item和用户的偏置项\n",
    "bi = np.zeros((n_items,1))    \n",
    "bu = np.zeros((n_users,1))   \n",
    "\n",
    "#item和用户的隐含向量\n",
    "qi =  np.zeros((n_items,K))    \n",
    "pu =  np.zeros((n_users,K))   \n",
    "\n",
    "\n",
    "for uid in range(n_users):  #对每个用户\n",
    "    pu[uid] = np.reshape(random((K,1))/10*(np.sqrt(K)),K)\n",
    "       \n",
    "for iid in range(n_items):  #对每个item\n",
    "    qi[iid] = np.reshape(random((K,1))/10*(np.sqrt(K)),K)\n",
    "\n",
    "#所有用户的平均打分\n",
    "mu = df_triplet_train['play_count'].mean()  #average rating"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.])"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bi[8]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [],
   "source": [
    "#根据当前参数，预测用户uid对Item（i_id）的打分\n",
    "def svd_pred(uid, iid):\n",
    "    #print('bi[iid],bu[uid],qi[iid],pu[uid]',bi[iid],bu[uid],qi[iid],pu[uid])\n",
    "    score = mu + bi[iid] + bu[uid] + np.sum(qi[iid]* pu[uid])  \n",
    "        \n",
    "    #将打分范围控制在1-5之间\n",
    "    #if score>5:  \n",
    "        #score = 5  \n",
    "    #elif score<1:  \n",
    "        #score = 1  \n",
    "        \n",
    "    return score  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "30015\n"
     ]
    }
   ],
   "source": [
    "#训练模型参数\n",
    "#gamma：为学习率\n",
    "#Lambda：正则参数\n",
    "#steps：迭代次数\n",
    "\n",
    "steps=50\n",
    "gamma=0.0001\n",
    "Lambda=0.15\n",
    "\n",
    "#总的打分记录数目\n",
    "n_records = df_triplet_train.shape[0]\n",
    "print(n_records)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The 0-th  step is running\n",
      "the rmse of this step on train data is  [35.31003471]\n",
      "The 1-th  step is running\n",
      "the rmse of this step on train data is  [35.17798852]\n",
      "The 2-th  step is running\n",
      "the rmse of this step on train data is  [35.04407028]\n",
      "The 3-th  step is running\n",
      "the rmse of this step on train data is  [34.89254523]\n",
      "The 4-th  step is running\n",
      "the rmse of this step on train data is  [34.70683776]\n",
      "The 5-th  step is running\n",
      "the rmse of this step on train data is  [34.46796543]\n",
      "The 6-th  step is running\n",
      "the rmse of this step on train data is  [34.15507054]\n",
      "The 7-th  step is running\n",
      "the rmse of this step on train data is  [33.75373242]\n",
      "The 8-th  step is running\n",
      "the rmse of this step on train data is  [33.24865592]\n",
      "The 9-th  step is running\n",
      "the rmse of this step on train data is  [32.63506766]\n",
      "The 10-th  step is running\n",
      "the rmse of this step on train data is  [31.94692005]\n",
      "The 11-th  step is running\n",
      "the rmse of this step on train data is  [31.20238896]\n",
      "The 12-th  step is running\n",
      "the rmse of this step on train data is  [30.45986551]\n",
      "The 13-th  step is running\n",
      "the rmse of this step on train data is  [29.76003023]\n",
      "The 14-th  step is running\n",
      "the rmse of this step on train data is  [29.13714093]\n",
      "The 15-th  step is running\n",
      "the rmse of this step on train data is  [28.60739291]\n",
      "The 16-th  step is running\n",
      "the rmse of this step on train data is  [28.17140608]\n",
      "The 17-th  step is running\n",
      "the rmse of this step on train data is  [27.82133877]\n",
      "The 18-th  step is running\n",
      "the rmse of this step on train data is  [27.54366851]\n",
      "The 19-th  step is running\n",
      "the rmse of this step on train data is  [27.32141433]\n",
      "The 20-th  step is running\n",
      "the rmse of this step on train data is  [27.14383351]\n",
      "The 21-th  step is running\n",
      "the rmse of this step on train data is  [27.0005312]\n",
      "The 22-th  step is running\n",
      "the rmse of this step on train data is  [26.87967107]\n",
      "The 23-th  step is running\n",
      "the rmse of this step on train data is  [26.77974471]\n",
      "The 24-th  step is running\n",
      "the rmse of this step on train data is  [26.69388303]\n",
      "The 25-th  step is running\n",
      "the rmse of this step on train data is  [26.61942338]\n",
      "The 26-th  step is running\n",
      "the rmse of this step on train data is  [26.55382144]\n",
      "The 27-th  step is running\n",
      "the rmse of this step on train data is  [26.49533362]\n",
      "The 28-th  step is running\n",
      "the rmse of this step on train data is  [26.44261822]\n",
      "The 29-th  step is running\n",
      "the rmse of this step on train data is  [26.39528761]\n",
      "The 30-th  step is running\n",
      "the rmse of this step on train data is  [26.35189674]\n",
      "The 31-th  step is running\n",
      "the rmse of this step on train data is  [26.31231232]\n",
      "The 32-th  step is running\n",
      "the rmse of this step on train data is  [26.27582987]\n",
      "The 33-th  step is running\n",
      "the rmse of this step on train data is  [26.24196415]\n",
      "The 34-th  step is running\n",
      "the rmse of this step on train data is  [26.2107659]\n",
      "The 35-th  step is running\n",
      "the rmse of this step on train data is  [26.1820101]\n",
      "The 36-th  step is running\n",
      "the rmse of this step on train data is  [26.15517933]\n",
      "The 37-th  step is running\n",
      "the rmse of this step on train data is  [26.13032657]\n",
      "The 38-th  step is running\n",
      "the rmse of this step on train data is  [26.10717051]\n",
      "The 39-th  step is running\n",
      "the rmse of this step on train data is  [26.08576232]\n",
      "The 40-th  step is running\n",
      "the rmse of this step on train data is  [26.06566497]\n",
      "The 41-th  step is running\n",
      "the rmse of this step on train data is  [26.04695786]\n",
      "The 42-th  step is running\n",
      "the rmse of this step on train data is  [26.02966876]\n",
      "The 43-th  step is running\n",
      "the rmse of this step on train data is  [26.01347281]\n",
      "The 44-th  step is running\n",
      "the rmse of this step on train data is  [25.99839141]\n",
      "The 45-th  step is running\n",
      "the rmse of this step on train data is  [25.98434474]\n",
      "The 46-th  step is running\n",
      "the rmse of this step on train data is  [25.97122594]\n",
      "The 47-th  step is running\n",
      "the rmse of this step on train data is  [25.95906103]\n",
      "The 48-th  step is running\n",
      "the rmse of this step on train data is  [25.94770028]\n",
      "The 49-th  step is running\n",
      "the rmse of this step on train data is  [25.93710461]\n"
     ]
    }
   ],
   "source": [
    "for step in range(steps):  \n",
    "    print ('The ' + str(step) + '-th  step is running' )\n",
    "    rmse_sum=0.0 \n",
    "            \n",
    "    #将训练样本打散顺序\n",
    "    kk = np.random.permutation(n_records)\n",
    "    for j in range(n_records):  \n",
    "        #每次一个训练样本\n",
    "        line = kk[j]  \n",
    "        \n",
    "        uid = users_index[df_triplet_train.iloc[line]['user']]\n",
    "#         print('uid',uid)\n",
    "        iid = items_index[df_triplet_train.iloc[line]['song']]\n",
    "#         print('iid',iid)\n",
    "        play_count  = df_triplet_train.iloc[line]['play_count']\n",
    "#         print('play_count',play_count)        \n",
    "        #预测残差\n",
    "        eui = play_count - svd_pred(uid, iid)  \n",
    "#         print('eui',eui)\n",
    "        #残差平方和\n",
    "        rmse_sum += eui**2  \n",
    "                \n",
    "        #随机梯度下降，更新\n",
    "        bu[uid] += gamma * (eui - Lambda * bu[uid])  \n",
    "        bi[iid] += gamma * (eui - Lambda * bi[iid]) \n",
    "                \n",
    "        temp = qi[iid]  \n",
    "        qi[iid] += gamma * (eui* pu[uid]- Lambda*qi[iid] )  \n",
    "        pu[uid] += gamma * (eui* temp - Lambda*pu[uid])  \n",
    "            \n",
    "    #学习率递减\n",
    "    gamma=gamma*0.93  \n",
    "    print (\"the rmse of this step on train data is \",np.sqrt(rmse_sum/n_records))  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [],
   "source": [
    "#保留模型参数\n",
    "# A method for saving object data to JSON file\n",
    "def save_json(filepath):\n",
    "    dict_ = {}\n",
    "    dict_['mu'] = mu\n",
    "    dict_['K'] = K\n",
    "    \n",
    "    dict_['bi'] = bi.tolist()\n",
    "    dict_['bu'] = bu.tolist()\n",
    "    \n",
    "    dict_['qi'] = qi.tolist()\n",
    "    dict_['pu'] = pu.tolist()\n",
    "\n",
    "    # Creat json and save to file\n",
    "    json_txt = json.dumps(dict_)\n",
    "    with open(filepath, 'w') as file:\n",
    "        file.write(json_txt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [],
   "source": [
    "# A method for loading data from JSON file\n",
    "def load_json(filepath):\n",
    "    with open(filepath, 'r') as file:\n",
    "        dict_ = json.load(file)\n",
    "\n",
    "        mu = dict_['mu']\n",
    "        K = dict_['K']\n",
    "\n",
    "        bi = np.asarray(dict_['bi'])\n",
    "        bu = np.asarray(dict_['bu'])\n",
    "    \n",
    "        qi = np.asarray(dict_['qi'])\n",
    "        pu = np.asarray(dict_['pu'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [],
   "source": [
    "save_json('svd_model.json')\n",
    "load_json('svd_model.json')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [],
   "source": [
    "#user：用户\n",
    "#返回推荐items及其打分（DataFrame）\n",
    "def svd_CF_recommend(user):\n",
    "    cur_user_id = users_index[user]\n",
    "    \n",
    "    #训练集中该用户打过分的item\n",
    "    cur_user_items = user_items[cur_user_id]\n",
    "\n",
    "    #该用户对所有item的打分\n",
    "    user_items_scores = np.zeros(n_items)\n",
    "\n",
    "    #预测打分\n",
    "    for i in range(n_items):  # all items \n",
    "        if i not in cur_user_items: #训练集中没打过分\n",
    "            user_items_scores[i] = svd_pred(cur_user_id, i)  #预测打分\n",
    "    \n",
    "    #推荐\n",
    "    #Sort the indices of user_item_scores based upon their value，Also maintain the corresponding score\n",
    "    sort_index = sorted(((e,i) for i,e in enumerate(list(user_items_scores))), reverse=True)\n",
    "    \n",
    "    #Create a dataframe from the following\n",
    "    columns = ['song', 'play_count']\n",
    "    df = pd.DataFrame(columns=columns)\n",
    "         \n",
    "    #Fill the dataframe with top 20 (n_rec_items) item based recommendations\n",
    "    #sort_index = sort_index[0:n_rec_items]\n",
    "    #Fill the dataframe with all items based recommendations\n",
    "    for i in range(0,len(sort_index)):\n",
    "        cur_item_index = sort_index[i][1] \n",
    "        cur_item = list (items_index.keys()) [list (items_index.values()).index (cur_item_index)]\n",
    "            \n",
    "        if ~np.isnan(sort_index[i][0]) and cur_item_index not in cur_user_items:\n",
    "            df.loc[len(df)]=[cur_item, sort_index[i][0]]\n",
    "    \n",
    "    return df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user</th>\n",
       "      <th>song</th>\n",
       "      <th>play_count</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>3325fe1d8da7b13dd42004ede8011ce3d7cd205d</td>\n",
       "      <td>SOURVJI12A58A7F353</td>\n",
       "      <td>63</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>e82b3380f770c78f8f067f464941057c798eaca2</td>\n",
       "      <td>SOKNWRZ12A8C13BF62</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>bdfca47d03157d26f1404075172128a6f8a3d39e</td>\n",
       "      <td>SOMNGMO12A6702187E</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>7ffc14a55b6256c9fa73fc5c5761d210deb7f738</td>\n",
       "      <td>SOGTQNI12AB0184A5C</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>083a2a59603a605275107c00812a811526c2a0af</td>\n",
       "      <td>SOXZOMB12AB017DA15</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                       user                song  play_count\n",
       "0  3325fe1d8da7b13dd42004ede8011ce3d7cd205d  SOURVJI12A58A7F353          63\n",
       "1  e82b3380f770c78f8f067f464941057c798eaca2  SOKNWRZ12A8C13BF62          19\n",
       "2  bdfca47d03157d26f1404075172128a6f8a3d39e  SOMNGMO12A6702187E           4\n",
       "3  7ffc14a55b6256c9fa73fc5c5761d210deb7f738  SOGTQNI12AB0184A5C           1\n",
       "4  083a2a59603a605275107c00812a811526c2a0af  SOXZOMB12AB017DA15           4"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_triplet_test = pd.read_csv('df_triplet_test.csv')\n",
    "df_triplet_test .head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "67c5b5b1982902d15badd8ce0c18b3278ec4bfc0 is a new user.\n",
      "\n",
      "62420be0fd0df5ab0eb4cba35a4bc7cb3e3b506a is a new user.\n",
      "\n",
      "3ab78e39bddeaeb789edad041fff03050077417c is a new user.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "#统计总的用户\n",
    "unique_users_test = df_triplet_test['user'].unique()\n",
    "\n",
    "#为每个用户推荐的item的数目\n",
    "n_rec_items = 10\n",
    "\n",
    "#性能评价参数初始化，用户计算Percison和Recall\n",
    "n_hits = 0\n",
    "n_total_rec_items = 0\n",
    "n_test_items = 0\n",
    "\n",
    "#所有被推荐商品的集合（对不同用户），用于计算覆盖度\n",
    "all_rec_items = set()\n",
    "\n",
    "#残差平方和，用与计算RMSE\n",
    "rss_test = 0.0\n",
    "\n",
    "#对每个测试用户\n",
    "for user in unique_users_test:\n",
    "    #测试集中该用户打过分的电影（用于计算评价指标的真实值）\n",
    "    if user not in users_index:   #user在训练集中没有出现过，新用户不能用协同过滤\n",
    "        print(str(user) + ' is a new user.\\n')\n",
    "        continue\n",
    "   \n",
    "    user_records_test= df_triplet_test[df_triplet_test.user == user]\n",
    "    \n",
    "    #对每个测试用户，计算该用户对训练集中未出现过的商品的打分，并基于该打分进行推荐（top n_rec_items）\n",
    "    #返回结果为DataFrame\n",
    "    rec_items = svd_CF_recommend(user)\n",
    "    for i in range(n_rec_items):\n",
    "        item = rec_items.iloc[i]['song']\n",
    "        \n",
    "        if item in user_records_test['song'].values:\n",
    "            n_hits += 1\n",
    "        all_rec_items.add(item)\n",
    "    \n",
    "    \n",
    "    #推荐的item总数\n",
    "    n_total_rec_items += n_rec_items\n",
    "    \n",
    "    #真实item的总数\n",
    "    n_test_items += user_records_test.shape[0]\n",
    "\n",
    "#Precision & Recall\n",
    "precision = n_hits / (1.0*n_total_rec_items)\n",
    "recall = n_hits / (1.0*n_test_items)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.044813278008298756"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "precision"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.043194240767897615"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "recall"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "基于用户的协同过滤precision：0.014384508990318118，recall：0.01386481802426343。  \n",
    "基于物品的协同过滤precision：0.021300138312586446，recall：0.020530595920543928。  \n",
    "实现基于模型（矩阵分解）的协同过滤precision：0.044813278008298756，recall：0.043194240767897615。  \n",
    "从结果看基于模型（矩阵分解）的协同过滤好于基于物品的协同过滤好于基于用户的协同过滤。\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
